#include <algorithm>
#include <cstdio>

typedef long long ll;
constexpr int N = 100005;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
int n, W, top, h[N], q[N], stk[N], pre[N];
ll f[N], w[N];

struct Node {
  ll ans, min, tag;
} tr[N << 2];

inline void pushup(int x) {
  tr[x].min = std::min(tr[x << 1].min, tr[x << 1 | 1].min);
  tr[x].ans = std::min(tr[x << 1].ans, tr[x << 1 | 1].ans);
}

inline void pushdown(int x) {
  static int ls, rs;
  if (tr[x].tag != inf) {
    ls = x << 1, rs = x << 1 | 1;
    tr[ls].min = tr[ls].ans + tr[x].tag;
    tr[rs].min = tr[rs].ans + tr[x].tag;
    tr[ls].tag = tr[rs].tag = tr[x].tag;
    tr[x].tag = inf;
  }
}

void build(int x, int l, int r) {
  tr[x].ans = tr[x].min = inf;
  if (l == r) return tr[x].tag = inf, void();
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
}

void update(int x, int l, int r, int pos) {
  if (l == r) return tr[x].min = inf, tr[x].ans = f[pos - 1], void();
  int mid = (l + r) >> 1;
  pushdown(x);
  if (pos <= mid)
    update(x << 1, l, mid, pos);
  else
    update(x << 1 | 1, mid + 1, r, pos);
  pushup(x);
}

void modify(int x, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return tr[x].min = tr[x].ans + v, tr[x].tag = v, void();
  int mid = (l + r) >> 1;
  pushdown(x);
  if (L <= mid) modify(x << 1, l, mid, L, R, v);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, v);
  pushup(x);
}

ll query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[x].min;
  int mid = (l + r) >> 1;
  ll res = inf;
  pushdown(x);
  if (L <= mid) res = std::min(res, query(x << 1, l, mid, L, R));
  if (mid < R) res = std::min(res, query(x << 1 | 1, mid + 1, r, L, R));
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P1848 [USACO12OPEN]Bookshelf G.in", "r", stdin);
  freopen("P1848 [USACO12OPEN]Bookshelf G.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &W);
  for (int i = 1; i <= n; ++i) scanf("%d%lld", &h[i], &w[i]), w[i] += w[i - 1];
  stk[++top] = 0, h[0] = inf;
  for (int i = 1; i <= n; ++i) {
    while (top && h[i] > h[stk[top]]) --top;
    pre[i] = stk[top];
    stk[++top] = i;
  }
  build(1, 1, n);
  for (int i = 1, l; i <= n; ++i) {
    update(1, 1, n, i);
    modify(1, 1, n, pre[i] + 1, i, h[i]);
    l = std::lower_bound(w, w + i + 1, w[i] - W) - w;
    if (l < i) f[i] = query(1, 1, n, l + 1, i);
  }
  printf("%lld", f[n]);
  return 0;
}